﻿using JinJun.YShow.BLL.IService;
using JinJun.YShow.Model;
using JinJun.YShow.Web.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace JinJun.YShow.Web.Controllers
{
    public class UserInfoController : BaseController
    {
        /*
        只定义了当前表的业务层，如需其他自行添加构造接口
           */

        private IUserInfoService _userInfoService;

        public UserInfoController(IUserInfoService userInfoService)
        {
            _userInfoService = userInfoService;
        }

        // GET: UserInfo
        public ActionResult Index()
        {
            return View();
        }
        public JsonResult GetAdminUserList(string username, string startdate, string enddate)
        {
            PageListResult<AddressAdmin> pageList = new PageListResult<AddressAdmin>();
            pageList.code = 0;
            pageList.msg = string.Empty;
            pageList.data = _userInfoService.GetAdminUserList(username, startdate, enddate);
            return Json(pageList, JsonRequestBehavior.AllowGet);
        }


        public JsonResult GetAdminbyid(int id)
        {
            UserInfo user = new UserInfo();
            user = _userInfoService.Query(a => a.Id == id);
            return Json(user);
        }

        public JsonResult Updateuser(UserInfo user)
        {
            UserInfo u1 = _userInfoService.Query(a => a.Id == user.Id);
            u1.Phone = user.Phone;
            u1.RealName = user.RealName;
            u1.UserName = user.UserName;
            OperateResult op = new OperateResult();
            op.Success = _userInfoService.Update(u1);
            return Json(op);
        }

        public JsonResult Updatezt(UserInfo user)
        {
            UserInfo u1 = _userInfoService.Query(a => a.Id == user.Id);
            u1.Status = user.Status;
            OperateResult op = new OperateResult();
            op.Success = _userInfoService.Update(u1);
            return Json(op);
        }


        public JsonResult Deleteuser(UserInfo user)
        {
            UserInfo u1 = _userInfoService.Query(a => a.Id == user.Id);
            OperateResult op = new OperateResult();
            op.Success = _userInfoService.Deleteuser(u1);
            return Json(op);
        }



        public JsonResult Vologin(AdminUser adminUser)
        {
            OperateResult op = new OperateResult();
            if (_userInfoService.Vologin(adminUser) != null)
            {
                op.Success = true;
            }
            return Json(op);
        }


        public JsonResult Getmenu(string modulename)
        {
            PageListResult<Menu> pageList = new PageListResult<Menu>();
            pageList.data = _userInfoService.GetMenuList(modulename);
            return Json(pageList);
        }
    } 
}